<?php
namespace Mentees\Controller;
use Common\Controller\BaseController;

class PublicController extends BaseController {
    //发送站内信页面
    public function sendMsg(){
    	$toid=I("toid");
    	$map['userid']=$toid;
        $userType = M('Member')->where($map)->getField("userType");
        if($userType==2){
            $list = M('Mentors')->where($map)->find();
        }else{
        	$list = M('Mentees')->where($map)->find();
        }
        $this->assign("list",$list);
        $this->display();
    }
    //请求拜师页面
    public function apply(){
    	$toid=I("toid");
    	$map['userid']=$toid;
        $userType = M('Member')->where($map)->getField("userType");
        if($userType==2){
            $list = M('Mentors')->where($map)->find();
        }else{
        	$list = M('Mentees')->where($map)->find();
        }
        $list['trainItem'] = trainStrtoArr($list['trainItem']);
        $where['id'] = array('in',$list['trainItem']);
        
        $list['trainItem'] = M('TrainCate')->field('name')->where($where)->select();
        $this->assign("list",$list);
        $this->display();
    }
    //聊天窗口页面
    public function chat(){
        $toid=I("toid");
        $map['userid']=$toid;
        $userType = M('Member')->where($map)->getField("userType");
        if($userType==2){
            $toUser = M('Mentors')->where($map)->find();
        }else{
            $toUser = M('Mentees')->where($map)->find();
        }
        unset($map);
        $map['userid']=\Think\Crypt\Driver\Xxtea::decrypt(cookie('userID'),C('cookie_fix'));
        $fromUser=M('Mentees')->where($map)->find();

        $this->assign("toUser",$toUser);
        $this->assign("fromUser",$fromUser);
        $this->display();
    }

    //评价窗口
    public function comment(){
        $toid=I("toid");
        $map['userid']=$toid;
        $userType = M('Member')->where($map)->getField("userType");
        if($userType==2){
            $list = M('Mentors')->where($map)->find();
        }else{
            $list = M('Mentees')->where($map)->find();
        }
        $this->assign("list",$list);

        unset($map);
        $map['toID']=$toid;
        $map['fromID']=\Think\Crypt\Driver\Xxtea::decrypt(cookie('userID'),C('cookie_fix'));
        $comment=M("Comment")->where($map)->find();
        $this->assign("comment",$comment);

        $this->display();
    }
}